<template>
  <div>
    <s-title text="趋势分析" />
    <div id="trendFenChart"></div>
  </div>
</template>

<script>
import sTitle from "../../common/sTitle.vue";
import axios from "axios";
export default {
  name: "trendFen",
  components: {
    sTitle,
  },
  data() {
    return {
      comps: [],
    };
  },
  mounted() {
    axios.get(this.$serverIp + "getQsfx").then((res) => {
      var echartData = { xData: [], yData: [] };
      echartData.yData[0] = [];
      echartData.yData[1] = [];
      for (let i = 0; i < res.data.length; i++) {
        echartData.xData.push(res.data[i].ny);
        echartData.yData[0].push(res.data[i].yps);
        echartData.yData[1].push(res.data[i].rps);
      }
      this.setEchartHandle(echartData);
    });
  },
  methods: {
    setEchartHandle(data) {
      let _echarts = this.$echarts.init(
        document.getElementById("trendFenChart"),
        null,
        { devicePixelRatio: 2 }
      );
      let option = {
        grid: {
          bottom: "15%",
          right: "5%",
          top: "15%",
        },
        legend: {
          data: ["黄牌", "红牌"],
          textStyle: {
            color: "#fff",
          },
        },
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: data.xData,
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
          axisLabel: {
            textStyle: {},
          },
        },
        yAxis: {
          type: "value",
          axisLabel: {
            formatter: "{value}",
            textStyle: {},
          },
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
        },
        series: [
          {
            name: "黄牌",
            data: data.yData[0],
            type: "line",
            itemStyle: {
              color: "rgba(255, 174, 0, 1)",
            },
            lineStyle: {
              color: "rgba(255, 174, 0, 1)",
            },
            areaStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(255, 174, 0, 1)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(255, 174, 0, 0)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
            smooth: true,
          },
          {
            name: "红牌",
            data: data.yData[1],
            type: "line",
            itemStyle: {
              color: "rgba(255, 50, 50, 1)",
            },
            lineStyle: {
              color: "rgba(255, 50, 50, 1)",
            },
            areaStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(255, 50, 50, 1)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(255, 50, 50, 0)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
            smooth: true,
          },
        ],
      };
      _echarts.setOption(option);
    },
  },
};
</script>
<style scoped>
#trendFenChart {
  width: 100%;
  height: 23vh;
  margin-top: 10px;
}
</style>
 